import {connect} from 'dva';
import React, {PureComponent} from 'react';
import {Form,Tooltip, Input, Upload, message, Switch, Icon, Select, Radio, Modal} from 'antd';
import styles from './UsercreateModal.less';

const FormItem = Form.Item;


@connect(state => ({
    service_order: state.service_order,
}))
@Form.create()
export default class ChangePriceModal extends PureComponent {
    state = {
        item: {},
    }
    handleSubmit = (e) => {
        const { service_order:{supportData},dispatch,form,item} = this.props
        
        form.validateFields((err, values) => {
            if (!err) {

                values.user_id = supportData.user_id;
                values.id = item.id;

                this.props.dispatch({
                    type: 'service_order/changeSupport',
                    payload: values,
                    callback: (result) => {
                      
                            this.props.form.resetFields();
                            this.handleCancel();
                        
                    },
                });
            }
        });
    }

    handleCancel = () => {
        this.props.dispatch({
            type: 'service_order/changePriceVisible',
            payload: false,
        });
        this.props.dispatch({
            type: 'service_order/changeChooseVisible',
            payload: false,
        });
    }
    render() {
        const {getFieldDecorator} = this.props.form;
        const item = this.state.item;
        const {service_order: { confirmLoading, priceVisible}} = this.props;

        const formItemLayout = {
            labelCol: {
                span: 6,
            },
            wrapperCol: {
                span: 14,
            },
        };
        return (
          <Modal
            onOk={this.handleSubmit}
            confirmLoading={confirmLoading}
            onCancel={this.handleCancel}
            title="修改价格"
            width="720"
            visible={priceVisible}
          >
          <Form >
          <FormItem
                  {...formItemLayout}
                  label={
                    <span>
                  订单价格
                  <em className={styles.optional}>
                      &nbsp;
                    <Tooltip title="订单价格">
                      <Icon type="info-circle-o" style={{marginRight: 4}} />
                    </Tooltip>
                  </em>
                    </span>
                      }
                >
                  {getFieldDecorator('price',{
                      rules: [{
                                    required: true,
                                    message: '请输入正确的订单价格',
                                    pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
                                }],})(
                       <Input />
                  )}
                </FormItem>
          </Form>  
          </Modal>
        );
    }
}

